<%@ Control Language="C#" ClassName="ContractConditions" Inherits="Dimok.Web.UI.TableControl" %>
<%@ Import Namespace="System.ComponentModel" %>
<script runat="server">
	[Bindable(true)]
	public string ContractConditionCode { set { ds.ContractConditionCode = value; } }
	protected override void OnInit(EventArgs e) {
		base.OnInit(e);
		ds.Selected += new ObjectDataSourceStatusEventHandler(ds_Selected);
	}

	void ds_Selected(object sender, ObjectDataSourceStatusEventArgs e) {
		System.Data.DataView dv = e.ReturnValue as System.Data.DataView;
		if (dv.Count == 1) grv.SelectedIndex = 0;
	}
</script>
<table>
<tr><td>
<ajaxtk:CollapsiblePanelExtender runat="server" ID="cpeCBT"
	TargetControlID="pnlCBT"
	CollapseControlID="pnlCBTHeader" ExpandControlID="pnlCBTHeader"
	TextLabelID="lblCBTLabel"
	ImageControlID="imgCBTPanel"
	CollapsedImage="~/images/Buttons/expand.jpg" ExpandedImage="~/images/Buttons/collapse.jpg"
	Collapsed="true"	CollapsedText="" ExpandedText=""
	SuppressPostBack="true"
></ajaxtk:CollapsiblePanelExtender>
<asp:Panel ID="pnlCBTHeader" CssClass="PanelHeaderBlue" style="width:100%" runat="server">
<table cellPadding="0" cellSpacing="0"><tr>
<th Width="1px"><asp:Image ID="imgCBTPanel" ImageUrl="~/images/Buttons/expand.jpg" runat="server" />
<td nowrap><label ID="lblCBTLabel" runat="server">Contract Conditions</label></td>
</tr></table>
</asp:Panel> 
<asp:Panel ID="pnlCBT" runat="server" CssClass="PannelContent">
<asp:UpdatePanel ID="upContractConditions" UpdateMode="Always" runat="server">
<ContentTemplate>
		<UI:GridViewEx ID="grv" runat="server" AutoGenerateColumns="False" DataSourceID="ds"
			ShowFooter="True" AllowSorting="True" DataKeyNames="Code">
			<Columns>

		<asp:TemplateField HeaderText="Code" SortExpression="Code">
			<ItemTemplate><%#Eval("Code")%></ItemTemplate>
			<EditItemTemplate><asp:TextBox ID="txtCode" Text='<%#Bind("Code")%>' runat="server" /></EditItemTemplate>
			<FooterTemplate><asp:TextBox ID="Code" runat="server" /></FooterTemplate>
		</asp:TemplateField>

		<asp:TemplateField HeaderText="Advance" SortExpression="Advance">
			<ItemStyle CssClass="Number" />
			<ItemTemplate><%#Eval("Advance", "{0:n0}%")%></ItemTemplate>
			<EditItemTemplate><asp:TextBox ID="txtAdvance" Text='<%#Bind("Advance")%>' runat="server" /></EditItemTemplate>
			<FooterTemplate><asp:TextBox ID="Advance" runat="server" /></FooterTemplate>
		</asp:TemplateField>

		<asp:TemplateField HeaderText="Payment" SortExpression="PaymentTypeID">
			<ItemTemplate><%#Eval("PaymentType")%></ItemTemplate>
			<EditItemTemplate><asp:DropDownList SelectedValue='<%# Bind("PaymentTypeID") %>'  ID="selPaymentTypeID" DataSourceID="dsPaymentTypes" DataTextField="Name" DataValueField="ID" runat="server" /></EditItemTemplate>
			<FooterTemplate><asp:DropDownList ID="PaymentTypeID" DataSourceID="dsPaymentTypes" DataTextField="Name" DataValueField="ID" runat="server" /></FooterTemplate>
		</asp:TemplateField>

		<asp:TemplateField HeaderText="Term(Max)" SortExpression="Term_Max">
			<ItemStyle CssClass="Number" />
			<ItemTemplate><%#Eval("Term_Max")%></ItemTemplate>
			<EditItemTemplate><asp:TextBox ID="txtTerm_Max" Text='<%#Bind("Term_Max")%>' runat="server" /></EditItemTemplate>
			<FooterTemplate><asp:TextBox ID="Term_Max" runat="server" /></FooterTemplate>
		</asp:TemplateField>

		<asp:TemplateField HeaderText="<span title='Amount Financed'>AF(Max)</span>" SortExpression="AF_Max">
			<ItemStyle CssClass="Number" />
			<ItemTemplate><%#Eval("AF_Max","{0:c0}")%></ItemTemplate>
			<EditItemTemplate><asp:TextBox ID="txtAF_Max" Text='<%#Bind("AF_Max")%>' runat="server" /></EditItemTemplate>
			<FooterTemplate><asp:TextBox ID="AF_Max" runat="server" /></FooterTemplate>
		</asp:TemplateField>

		<asp:TemplateField HeaderText="Interest" SortExpression="InterestBasisID">
			<ItemTemplate><%#Eval("InterestBasis")%></ItemTemplate>
			<EditItemTemplate><asp:DropDownList SelectedValue='<%# Bind("InterestBasisID") %>'  ID="selInterestBasisID" DataSourceID="dsInterestBasis" DataTextField="Name" DataValueField="ID" runat="server" /></EditItemTemplate>
			<FooterTemplate><asp:DropDownList ID="InterestBasisID" DataSourceID="dsInterestBasis" DataTextField="Name" DataValueField="ID" runat="server" /></FooterTemplate>
		</asp:TemplateField>

		<asp:TemplateField HeaderText="SellPrice/AF<br>Ratio(Max)" SortExpression="SellPriceRatio_Max">
			<ItemStyle CssClass="Number" />
			<ItemTemplate><%#Eval("SellPriceRatio_Max", "{0:n0}%") + "/" + Eval("AFRatio_Max", "{0:n0}%")%></ItemTemplate>
			<EditItemTemplate>
				<asp:TextBox ID="txtSellPriceRatio_Max" style="width:35%" Text='<%#Bind("SellPriceRatio_Max")%>' runat="server" />/
				<asp:TextBox ID="txtAFRatio_Max" style="width:35%" Text='<%#Bind("AFRatio_Max")%>' runat="server" />
			</EditItemTemplate>
			<FooterTemplate>
				<asp:TextBox ID="SellPriceRatio_Max" style="width:35%" runat="server" />/
				<asp:TextBox ID="AFRatio_Max" style="width:35%" runat="server" />
			</FooterTemplate>
		</asp:TemplateField>

		<asp:TemplateField HeaderText="Fee(%)/<br>Fee($)" SortExpression="Fee_Max">
			<ItemStyle CssClass="Number" />
			<ItemTemplate><%#Eval("FeeRate", "{0:n0}%") + "/" + Eval("Fee_Max", "{0:c0}")%></ItemTemplate>
			<EditItemTemplate>
				<asp:TextBox ID="txtFeeRate" style="width:20%" Text='<%#Bind("FeeRate")%>' runat="server" />/
				<asp:TextBox ID="txtFee_Max" style="width:40%" Text='<%#Bind("Fee_Max")%>' runat="server" />
			</EditItemTemplate>
			<FooterTemplate>
				<asp:TextBox ID="FeeRate" style="width:20%" runat="server" />/
				<asp:TextBox ID="Fee_Max" style="width:40%" runat="server" />
			</FooterTemplate>
		</asp:TemplateField>

		<asp:TemplateField HeaderText="<span title='Overage Ratio/Overage Allowed'>Ovg(%)/<br>Ovg($)</span>" SortExpression="OverageFeeRatio">
			<ItemStyle CssClass="Number" />
			<ItemTemplate><%#Eval("OverageFeeRatio", "{0:n0}%") + "/" + Eval("OverageAllowed", "{0:c0}")%></ItemTemplate>
			<EditItemTemplate>
				<asp:TextBox ID="txtOverageFeeRatio" style="width:10%" Text='<%#Bind("OverageFeeRatio")%>' runat="server" />/
				<asp:TextBox ID="txtOverageAllowed" style="width:40%" Text='<%#Bind("OverageAllowed")%>' runat="server" />
			</EditItemTemplate>
			<FooterTemplate>
				<asp:TextBox ID="OverageFeeRatio" style="width:10%" runat="server" />/
				<asp:TextBox ID="OverageAllowed" style="width:40%" runat="server" />
			</FooterTemplate>
		</asp:TemplateField>

		<asp:TemplateField HeaderText="Car Book" SortExpression="CarBookTypeID">
			<ItemTemplate><%#Eval("CarBookType")%></ItemTemplate>
			<EditItemTemplate><asp:DropDownList SelectedValue='<%# Bind("CarBookTypeID") %>'  ID="selCarBookTypeID" DataSourceID="dsCarBooks" DataTextField="Name" DataValueField="ID" runat="server" /></EditItemTemplate>
			<FooterTemplate><asp:DropDownList ID="CarBookTypeID" DataSourceID="dsCarBooks" DataTextField="Name" DataValueField="ID" runat="server" /></FooterTemplate>
		</asp:TemplateField>

		<asp:TemplateField HeaderText="<span title='Down Payment '>DP(Min)</span>" SortExpression="DownPayment_Min">
			<ItemStyle CssClass="Number" />
			<ItemTemplate><%#Eval("DownPayment_Min", "{0:n0}%")%></ItemTemplate>
			<EditItemTemplate><asp:TextBox ID="txtDownPayment_Min" Text='<%#Bind("DownPayment_Min")%>' runat="server" /></EditItemTemplate>
			<FooterTemplate><asp:TextBox ID="DownPayment_Min" runat="server" /></FooterTemplate>
		</asp:TemplateField>

		<asp:TemplateField HeaderText="DTI(Max)" SortExpression="DTI_Max">
			<ItemStyle CssClass="Number" />
			<ItemTemplate><%#Eval("DTI_Max","{0:n0}%")%></ItemTemplate>
			<EditItemTemplate><asp:TextBox ID="txtDTI_Max" Text='<%#Bind("DTI_Max")%>' runat="server" /></EditItemTemplate>
			<FooterTemplate><asp:TextBox ID="DTI_Max" runat="server" /></FooterTemplate>
		</asp:TemplateField>

		<asp:TemplateField HeaderText="Job Time(Min)" SortExpression="JobTime_Min">
			<ItemStyle CssClass="Number" />
			<ItemTemplate><%#Eval("JobTime_Min")%></ItemTemplate>
			<EditItemTemplate><asp:TextBox ID="txtJobTime_Min" Text='<%#Bind("JobTime_Min")%>' runat="server" /></EditItemTemplate>
			<FooterTemplate><asp:TextBox ID="JobTime_Min" runat="server" /></FooterTemplate>
		</asp:TemplateField>

		<asp:TemplateField HeaderText="Jobs In 2 Yrs" SortExpression="JobsCountIn2Years_Max">
			<ItemStyle CssClass="Number" />
			<ItemTemplate><%#Eval("JobsCountIn2Years_Max")%></ItemTemplate>
			<EditItemTemplate><asp:TextBox ID="txtJobsCountIn2Years_Max" Text='<%#Bind("JobsCountIn2Years_Max")%>' runat="server" /></EditItemTemplate>
			<FooterTemplate><asp:TextBox ID="JobsCountIn2Years_Max" runat="server" /></FooterTemplate>
		</asp:TemplateField>

		<asp:TemplateField HeaderText="Res. Time(Min)" SortExpression="ResidenceTime_Min">
			<ItemStyle CssClass="Number" />
			<ItemTemplate><%#Eval("ResidenceTime_Min")%></ItemTemplate>
			<EditItemTemplate><asp:TextBox ID="txtResidenceTime_Min" Text='<%#Bind("ResidenceTime_Min")%>' runat="server" /></EditItemTemplate>
			<FooterTemplate><asp:TextBox ID="ResidenceTime_Min" runat="server" /></FooterTemplate>
		</asp:TemplateField>

		<asp:TemplateField HeaderText="Time In Area(Min)" SortExpression="AreaTime_Min">
			<ItemStyle CssClass="Number" />
			<ItemTemplate><%#Eval("AreaTime_Min")%></ItemTemplate>
			<EditItemTemplate><asp:TextBox ID="txtAreaTime_Min" Text='<%#Bind("AreaTime_Min")%>' runat="server" /></EditItemTemplate>
			<FooterTemplate><asp:TextBox ID="AreaTime_Min" runat="server" /></FooterTemplate>
		</asp:TemplateField>

		<asp:TemplateField HeaderText="Car Age(Max)" SortExpression="ModelAge_Max">
			<ItemStyle CssClass="Number" />
			<ItemTemplate><%#Eval("ModelAge_Max")%></ItemTemplate>
			<EditItemTemplate><asp:TextBox ID="txtModelAge_Max" Text='<%#Bind("ModelAge_Max")%>' runat="server" /></EditItemTemplate>
			<FooterTemplate><asp:TextBox ID="ModelAge_Max" runat="server" /></FooterTemplate>
		</asp:TemplateField>

		<asp:TemplateField HeaderText="<span title='Mileage Per Year(Max)/Maximum Miles'>MPY/<br>Miles(Max)</span>" SortExpression="MileAgePerYear_Max">
			<ItemStyle CssClass="Number" Wrap="true" />
			<ItemTemplate>
				<div style="word-break:break-all">
					<%#Convert.ToInt32(Eval("MileAgePerYear_Max"))/1000+"K/"+(int)Eval("Miles_Max")/1000+"K"%>
				</div>
			</ItemTemplate>
			<EditItemTemplate>
				<asp:TextBox ID="txtMileAgePerYear_Max" Text='<%#Bind("MileAgePerYear_Max")%>' style="width:40%" runat="server" />
				<asp:TextBox ID="txtMiles_Max" Text='<%#Bind("Miles_Max")%>' style="width:40%" runat="server" />
			</EditItemTemplate>
			<FooterTemplate>
				<asp:TextBox ID="MileAgePerYear_Max" style="width:40%" runat="server" />/
				<asp:TextBox ID="Miles_Max" style="width:40%" runat="server" />
			</FooterTemplate>
		</asp:TemplateField>

		<asp:TemplateField HeaderText="<span title='Service Contract Maximum'>Srv.Contr.(Max)</span>" SortExpression="ServiceContract_Max">
			<ItemStyle CssClass="Number" />
			<ItemTemplate><%#Eval("ServiceContract_Max","{0:c0}")%></ItemTemplate>
			<EditItemTemplate><asp:TextBox ID="txtServiceContract_Max" Text='<%#Bind("ServiceContract_Max")%>' runat="server" /></EditItemTemplate>
			<FooterTemplate><asp:TextBox ID="ServiceContract_Max" runat="server" /></FooterTemplate>
		</asp:TemplateField>

		<asp:TemplateField HeaderText="<span title='Recourse Months'>Rec.Mos.</span>" SortExpression="RecourseMonths">
			<ItemStyle CssClass="Number" />
			<ItemTemplate><%#Eval("RecourseMonths")%></ItemTemplate>
			<EditItemTemplate><asp:TextBox ID="txtRecourseMonths" Text='<%#Bind("RecourseMonths")%>' runat="server" /></EditItemTemplate>
			<FooterTemplate><asp:TextBox ID="RecourseMonths" runat="server" /></FooterTemplate>
		</asp:TemplateField>

		<asp:TemplateField HeaderText="<span title='Tracking Device Reward'>TDR</span>" SortExpression="TrackerReward">
			<ItemStyle CssClass="Number" />
			<ItemTemplate><%#Eval("TrackerReward")%></ItemTemplate>
			<EditItemTemplate><asp:TextBox ID="txtTrackerReward" Text='<%#Bind("TrackerReward")%>' runat="server" /></EditItemTemplate>
			<FooterTemplate><asp:TextBox ID="TrackerReward" runat="server" /></FooterTemplate>
		</asp:TemplateField>

		<asp:TemplateField HeaderText="<span title='Deduct Fees from Reserve'>DFR</span>" SortExpression="DeductFeeFromReserve" ItemStyle-HorizontalAlign="Center">
			<ItemTemplate><%#(bool)Eval("DeductFeeFromReserve")?"Y":""%></ItemTemplate>
			<EditItemTemplate><asp:CheckBox ID="txtDeductFeeFromReserve" Checked='<%#Bind("DeductFeeFromReserve")%>' runat="server" /></EditItemTemplate>
			<FooterTemplate><asp:CheckBox ID="DeductFeeFromReserve" runat="server" /></FooterTemplate>
		</asp:TemplateField>

			</Columns>
		</UI:GridViewEx>
<DS:ContractConditionsDataSource ID="ds" runat="server" />
<DS:ContractPaymentTypesDataSource ID="dsPaymentTypes" runat="server" />
<DS:ContractInterestBasisDataSource ID="dsInterestBasis" runat="server" />
<DS:CarBookTypesDataSource id="dsCarBooks" runat="server" />
</ContentTemplate>
</asp:UpdatePanel>
</asp:Panel>
</td>
</tr>
</table>
